package operation;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Yang
 * Package: operation
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-15
 * Time: 20:54
 */

public class Yang {
    //杨辉三角
    public static void main(String[] args) {

        //1.创建一个二维数组 每行的列不确定 就不写
        int[][] arr = new int[10][];

        //2.初始化 外层数组元素
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[i + 1];
            //给数组每行的首末元素赋值为1
            arr[i][0] = 1;
            //arr[i][i] = 1;
            arr[i][arr[i].length - 1] = 1;
            //给数组每行的非首末元素赋值
            for (int j = 1; j < arr[i].length - 1; j++) { //从每行的第二个元素 开始 到倒数第二个元素结束
                arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
            }
        }


        //遍历二维数组
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }


    }
}
